package com.da.javatest.leetCode2;

import java.util.ArrayList;
import java.util.List;

public class Code83 {
    private List<Integer> list = new ArrayList<>();

    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) {
            return null;
        }
        getList(head);
        ListNode l = new ListNode(list.get(0));
        setList(l, 1);
        return l;
    }

    private void setList(ListNode node, int index) {
        if (index < list.size()) {
            node.next = new ListNode(list.get(index));
            setList(node.next, index += 1);
        }
    }

    private void getList(ListNode node) {
        if (node != null) {
            if (!list.contains(node.val)) {
                list.add(node.val);
            }
            getList(node.next);
        }
    }
}
